import { getEquipListApi, getMusicListApi } from "@/api/modules/baseApi";
import { defineStore } from "pinia";
import { baseInfoState } from "../interface";
import piniaPersistConfig from "../helper/persist";

export const useBaseInfoStore = defineStore({
  id: "baseInfo",
  state: (): baseInfoState => ({
    equipList: [],
    musicList: [],
  }),
  getters: {},
  actions: {
    /**
     * @use 获取设备信息
     */
    async getEquiptList() {
      try {
        const { data } = await getEquipListApi();
        this.equipList = data;
      } catch (error) {}
    },

    /**
     * @use 获取音乐信息
     */
    async getMusicList() {
      try {
        const { data } = await getMusicListApi();

        const key = Object.keys(data);
        const res = key.map((item) => {
          return {
            name: item,
            list: data[item],
            isChecked: false,
          };
        });

        this.musicList = res;
      } catch (error) {}
    },
  },
  persist: piniaPersistConfig("baseInfo"),
});
